#include <QtDebug>
#include "plurksettings.h"

#define COOKIE_GROUP    "Cookie"
#define OAUTH_APPKEY    "OAUTH_APPKEY"
#define OAUTH_APPSECRET "OAUTH_APPSECRET"
#define INI_ORGANIZATION "MeeGo Plurker"

PlurkSettings *PlurkSettings::_instance = NULL;

PlurkSettings::PlurkSettings(QObject *parent) :
    QObject(parent), inifile(INI_ORGANIZATION)
{
}

PlurkSettings *PlurkSettings::instance()
{
  return _instance;
}

void PlurkSettings::storeCookies(const QString &name, const QVariant &value)
{
  inifile.beginGroup(COOKIE_GROUP);
  inifile.setValue(name, value);
  inifile.endGroup();
  inifile.sync();
}

const QVariant PlurkSettings::cookie(const QString &name)
{
  QVariant variant;
  inifile.beginGroup(COOKIE_GROUP);
  variant = inifile.value(name);
  inifile.endGroup();

  return variant;
}

const QStringList PlurkSettings::cookieKeys()
{
  QStringList list;

  inifile.beginGroup(COOKIE_GROUP);
  list = inifile.childKeys();
  inifile.endGroup();

  return list;
}

void PlurkSettings::storeOAuthKeys(const QString &appKey, const QString &appSecret)
{
  inifile.setValue(OAUTH_APPKEY, appKey);
  inifile.setValue(OAUTH_APPSECRET, appSecret);
  inifile.sync();
}

const QVariant PlurkSettings::oauthAppKey()
{
  return inifile.value(OAUTH_APPKEY);
}

const QVariant PlurkSettings::oauthAppSecret()
{
  return inifile.value(OAUTH_APPSECRET);
}
